Skip to content

quality of life fix for pip users#1289

Open
James11222 wants to merge 2 commits into
LSSTDESC:masterfrom
James11222:fix_pypi
Open

quality of life fix for pip users#1289
James11222 wants to merge 2 commits into
LSSTDESC:masterfrom
James11222:fix_pypi

Conversation

@James11222
Copy link
Copy Markdown

This pull request adds quality-of-life support for pip users by adding optional dependency groups in pyccl, making it easier for users to install only the packages they need for specific functionalities (e.g., Boltzmann codes, perturbation theory, emulators). It updates the documentation to explain these new installation options, improves error handling for missing optional dependencies, and sets the default transfer function based on installed packages.

Existing Issue this Fixes: when you install the base package via pip, Boltzmann codes are not installed but the default transfer_function in ccl.Cosmology() is 'boltzmann_camb'. This creates a problem when you go to use the cosmology object in components of the halo model for example. Now with these changes, I've made the default behavior be that if the Boltzmann codes are not installed, 'eisenstein_hu' is the default, otherwise camb is the default (I believe the default behavior in the conda installation).

Dependency management and installation:

  • Added optional dependency groups (boltzmann, pt, emulators, full) to pyproject.toml for easier installation of extra features.
  • Updated installation instructions in both README.md and readthedocs/source/installation.rst to document the new extras and clarify default behaviors depending on installed packages. [1] [2] [3] [4] [5]
pip install pyccl[boltzmann]   # Boltzmann codes: CAMB, CLASS (classy), ISiTGR
pip install pyccl[pt]          # Perturbation theory: FAST-PT, velocileptors
pip install pyccl[emulators]   # Emulators: BaccoEmu, MiraTitan, Dark Emulator
pip install pyccl[full]        # All of the above

Default behavior and configuration:

  • The default transfer_function is now set based on whether camb is installed: 'boltzmann_camb' if available, otherwise 'eisenstein_hu'. [1] [2]

Error handling improvements:

  • Improved error messages in pyccl/boltzmann.py to raise a CCLError with clear installation instructions if a required optional dependency (CAMB, CLASS/classy, ISiTGR) is missing, instead of a generic ImportError. [1] [2] [3]
  • Updated tests to expect the new CCLError when optional dependencies are missing.

@carlosggarcia
Copy link
Copy Markdown
Collaborator

Thanks for the PR! I think it's a great idea to allow this selection of packages. I have not reviewed the code yet so just two quick comments:

  • You will need to update the branch before I can merge it. I will merge first Automatic wheels building for PyPI #1290 so wait for that.
  • We should not change the default transfer_function. That is an API change, which would require major version bump and might break some codes in a way that might not be easy no notice (because they will work but with the wrong transfers). So, revert that back to boltzmann_camb.

Once #1290 is merged I'll come back to this PR.

Copy link
Copy Markdown
Collaborator

@carlosggarcia carlosggarcia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the work! Just a few requests.


with mock.patch.dict(sys.modules, {'isitgr': None}):
with pytest.raises(ModuleNotFoundError):
with pytest.raises(ccl.CCLError):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change? Isn't ModuleNotFoundError a more explicit error?

Comment thread pyccl/cosmology.py
return False


_DEFAULT_TRANSFER_FUNCTION = 'boltzmann_camb' if _camb_available() else 'eisenstein_hu'
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have to keep 'boltzmann_camb' as default to avoid changing the API. Also, I don't think it's a good idea to have this kind of automatic changes depending on what's installed because one can end up with the wrong transfer function inadvertently.

Comment thread pyccl/cosmology.py
T_CMB=DefaultParams.T_CMB,
T_ncdm=DefaultParams.T_ncdm,
transfer_function='boltzmann_camb',
transfer_function=_DEFAULT_TRANSFER_FUNCTION,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As said above. Revert this.

Comment thread README.md
pip install pyccl[full] # All of the above
```

Without `pyccl[boltzmann]`, the default `transfer_function` is `'eisenstein_hu'`.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I said above, we won't change the default transfer function so remove these lines.

Comment thread pyproject.toml
"pytest-cov",
]

boltzmann = ["camb", "classy", "isitgr"]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i would keep isitgr out and create it its own optional set e.g. MG, since most people won't need it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants